<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>车辆信息修改</title>
    <link rel="stylesheet" href="../../lib/layui/css/layui.css">
    <link rel="stylesheet" href="../../css/okadmin.css">
</head>
<body>
<fieldset class="layui-elem-field layui-field-title" style="margin-top: 20px;">
    <legend>车辆信息修改</legend>
</fieldset>
<div class="layui-fluid">
    <div class="layui-card">
        <div class="layui-form">
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">I&#12288;&#12288;&#12288;D</label>
                        <div class="layui-input-block ">
                            <input type="text" id="vehicleId" name="vehicleId"
                                   style="background-color: #dcdcdc" disabled
                                   placeholder="" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">车&#12288;&#12288;牌</label>
                        <div class="layui-input-block ">
                            <input id="licensePlateNumber" name="licensePlateNumber" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder=""  autocomplete="off">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">名&#12288;&#12288;称</label>
                        <div class="layui-input-block ">
                            <input id="vehicleName" name="vehicleName" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" autocomplete="off">
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">类&#12288;&#12288;型</label>
                        <div class="layui-input-block">
                            <select name="type" id="type" style="float: left;position: relative;" lay-search>
                                <option value="0">手动挡</option>
                                <option value="1">自动挡</option>
                            </select>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">所属教练</label>
                        <div class="layui-input-block ">
                            <select name="coachs" id="coachs" style="float: left;position: relative;" lay-search>
                            </select>
                        </div>
                    </div>
                </div>
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">价格</label>
                        <div class="layui-input-block ">
                            <input id="price" name="price" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" autocomplete="off">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6">
                    <div class="layui-inline">
                        <label class="layui-form-label">备注</label>
                        <div class="layui-input-block ">
                            <input id="remark" name="remark" type="text" style="float: left;position: relative;"
                                   class="layui-input"
                                   placeholder="" autocomplete="off">
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-form-item">
                <div class="layui-col-xs6" style="float: right;margin-right: 10%">
                    <div class="layui-inline">
                        <button class="layui-btn layui-btn-normal layuiadmin-btn-list" lay-submit id="update">
                            更改
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
<script src="../../lib/layui/layui.js"></script>
<script src="../../js/jquery.min.js"></script>
<script src="../../js/application.js"></script>
<script>
    var coachId="";
    function init(){
        htmlSetValue("vehicleId")
        htmlSetValue("licensePlateNumber")
        htmlSetValue("vehicleName")
        htmlSetValue("type")
        htmlSetValue("coachId",function(v){
            var fullname=GetQueryString("fullname");
            if(v!=""){
                coachId=v
                var option = "<option value='" + v + "'>" + fullname + "</option>";
                $("#coachs").append(option);
            }else{
                var option='<option value="">无教练</option>'
                $("#coachs").append(option);
            }
        })
        htmlSetValue("price")
        htmlSetValue("remark")
    }
    layui.use('form', function () {
        var form = layui.form;
        init()
        form.render();
        myAjax(mainUri + '/vCoach/selects', {page: -1,possessVehicle:1}, function (datas) {
            var list = datas['data'];
            var option;
            for (var i = 0; i < list.length; i++) {
                {
                    option += "<option value='" + list[i]['coachId'] + "'>" + list[i]['fullname'] + "</option>";
                }
            }
            $("#coachs").append(option);
            form.render();
        })

        $("#update").on('click',function() {
            if ($('#vehicleId').val() == "" || $('#licensePlateNumber').val() == "") {
                return;
            }
            var type = $("#type").find("option:checked").val();//类型
            var coach = $("#coachs").find("option:checked").val();//教练
            var msg = "确定修改id为 " + $('#vehicleId').val() + "的车辆的信息?";
            var data = {
                vehicleId: $('#vehicleId').val(),
                licensePlateNumber: $('#licensePlateNumber').val(),
                vehicleName: $('#vehicleName').val(),
                price: $('#price').val(),
                remark: $('#remark').val(),
                type: type,
                coachId: coach
            };
            if (coach == coachId) {
                data["coachId"] = ""
            }
            layer.confirm(msg, function (index) {
                showloading(true)
                myAjax(mainUri + "/vehicle/update", data, function (d) {
                    if (d['code'] == '0') {
                        layer.msg(d['msg'], {
                            icon: 1, time: 2000, end: function () {
                                var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                                parent.layer.close(index);
                            }
                        })
                    } else {
                        alert(d['msg'])
                    }
                })
                showloading(false)
            })
        })
    });
</script>
</html>